<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||	
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws. 
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.). 
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations). 
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Groups/classes/PhpFox_ComponentMemberList.class.php, $Author:  $ */



/** Component for group member list on the separate page
 * @version $Id: PhpFox_ComponentMemberList.class.php 
 *  Max Kovrigovich
 * @package module.groups
 */
class PhpFox_Mod_Groups_ComponentMemberList extends BaseComponent
{
    /** Processing method
     */
    function process()
    {
        //check permissions
        $oSecurityService = App::getModuleService('Account', 'Security');
		/* @var $oSecurityService PhpFox_Mod_Account_ServiceSecurity */
		$oSecurityService->checkPerm('groups', array('read_only', 'full'));
		
        $oGroupsService = $this->_oModule->getService('Groups');
        /* @var $oGroupsService PhpFox_Mod_Groups_ServiceGroups */

        App::loadClass('Pager');
        
        $oReq = &App::getRequest();
        /* @var $oReq Request */
         
        $oUrl = &App::getUrl();
        /* @var $oUrl Url */ 
        
        $oTpl = $this->_oModule->getTemplate();
        
        $iGroupId = $oReq->getInt('id', 0);
        $iDeleteId = $oReq->getInt('delete', 0);

        $oUser = $this->getParam('user');

        $bIsGroupOwner = $oGroupsService->isOwner($iGroupId, App::getUser('user'));
        $bIsMember = (App::getUser('user') ? $oGroupsService->isMember($iGroupId, App::getUser('user')) : false);
        $aGroupData = $oGroupsService->getGroupData($iGroupId);
    	if(!($bIsMember OR App::isStaff()) && $aGroupData['hide_group'] == 'Yes' )
        {
        	App::gotoUrl('public.groups.private',array('id'=>$iGroupId));
        }
        if($iGroupId)
        {
	        if($iDeleteId && ($bIsGroupOwner OR App::isStaff()))
	        {
	            //delete
	            $oGroupsService->deleteFromGroup($iDeleteId, App::getUser('user'));
	        }
        }
        
        $iPageSize = 10;
        $iPage = $oReq->getInt('page', 1);
        list($iCnt, $aMembers) = $oGroupsService->getGroupMember($iGroupId, $iPage, $iPageSize);
        
        $oPager = &new Pager($iCnt, $iPage, $iPageSize);
        
        $iFrom = $oPager->getOffset($iPage, $iPageSize);
        //if($iFrom < 1) $iFrom = 1;
        $iTo = (($iFrom + $iPageSize) > $iCnt) ? $iCnt : ($iFrom + $iPageSize); 
 
        $aGroupData = $oGroupsService->getGroupData($iGroupId);
        
        $oTpl->assign(array(
            'sUser'         => App::getUser('user'),
            'iFrom'         => ($iCnt) ? ($iFrom + 1) : 0,
            'iTo'           => $iTo,
            'bIsGroupOwner' => $bIsGroupOwner,
            'iGroupId'      => $iGroupId,
            'aGroupData'    => $aGroupData,
            'aMembers'	    => $aMembers,
            'aPaging'       => $oPager->getInfo($oUrl),
            'iCnt'          => $iCnt,
	        'sImageUrl'     => App::getParam('user.pic.url'), 
	        'bIsAdmin'		=> App::isStaff(),
        ));
        $sHtml = $oTpl->fetch('MemberList.html');
        return $sHtml;
    }
}
?>